package main

import (
	"gitee.com/Luna-CY/Golang-Project-Template/entry/http/gateway/example"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/configuration"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/http"
	"github.com/spf13/cobra"
)

func NewHttpExampleCommand() *cobra.Command {
	var command = &cobra.Command{
		Use:   "example",
		Short: "启动示例HTTP服务器",
		Args:  cobra.NoArgs,
		Run: func(cmd *cobra.Command, args []string) {
			// set listening address if not set in configuration.Configuration.Server.Http.Example.Listen, default to ":8000"
			if "" == configuration.Configuration.Server.Http.Example.Listen {
				configuration.Configuration.Server.Http.Example.Listen = ":8000"
			}

			http.Listen(cmd, configuration.Configuration.Server.Http.Example.Listen, configuration.Configuration.Server.Http.Example.GinTrustedProxies, configuration.Configuration.Server.Http.Example.UnderMaintenance, example.Register)
		},
	}

	return command
}
